package com.lai.hospital.controller;

import com.lai.hospital.annotation.OptLog;
import com.lai.hospital.constant.OptTypeConst;
import com.lai.hospital.entity.Hospital;
import com.lai.hospital.service.HospitalService;
import com.lai.hospital.vo.ConditionVO;
import com.lai.hospital.vo.HospitalVO;
import com.lai.hospital.vo.PageResult;
import com.lai.hospital.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * @author : lai
 * @version V1.0
 * @Project: hospital-springboot
 * @Package com.lai.hospital.controller
 * @Description: 医院控制器
 * @date Date : 2022年11月22日 14:18
 */
@RestController
@Api(tags = "医院模块")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;


    @GetMapping("/admin/hospitals")
    @ApiOperation(value = "后台查看医院")
    public Result<PageResult<Hospital>> listHospital(ConditionVO conditionVO){
        return Result.ok(hospitalService.listHospitalBack(conditionVO));
    }


    @OptLog(optType= OptTypeConst.UPDATE)
    @PutMapping("/admin/updateHospital")
    @ApiOperation(value = "修改医院")
    public Result<?> updateHospital(@Valid @RequestBody HospitalVO hospitalVO){
        hospitalService.updateHospital(hospitalVO);
        return Result.ok();
    }

    /**
     * 更新医院缩略图
     *
     * @param file 文件
     * @return {@link Result<String>} 缩略图地址
     */
    @ApiOperation(value = "更新医院缩略图")
    @ApiImplicitParam(name = "file", value = "医院缩略图", required = true, dataType = "MultipartFile")
    @PostMapping("/admin/hospital/cover")
    public Result<String> updateUserAvatar(MultipartFile file) {
        return Result.ok(hospitalService.updateHospitalCover(file));
    }

    @GetMapping("/user/hospital")
    @ApiOperation(value = "用户查看医院信息")
    public Result<?> selectHospitalInfo(){
        return Result.ok(hospitalService.getHospitalInfo());
    }



}
